<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>平方</title>
</head>
<body>
<input type="text" id="i1">
<input type="button" value="平方" onclick="fn()">
<div>结果:0</div>

<script>
    function fn() {
        let i = document.querySelector("#i1");
        let d = document.querySelector("div");
        if(!isNaN(i.value)) {
            //得到的是一个字符串,如果做加法运算则变成拼接,要先将字符串转为Int类型
            // parseInt(i.value);
            // i.value*1;
            d.innerText = "结果:" + (i.value*1 + i.value*1);
        }else {
            d.innerText = "输入的数据有误,请重新输入!"
        }

    }
</script>
</body>
</html>